﻿







function YZname() {
    if (document.getElementById('txtName').value == '') {
        alert('套餐名称不能为空！')
        return false;
    }
   
            var he1 = parseInt(document.getElementById('txtallnum2').value);
            var he2 = parseInt(document.getElementById('txtTotal2').value);

            if ((he1 - he2) < 0) {
                alert('不能低于最低分数！');
                return false;
            }
            

    return true;
}





function CheckAll(o) {
    $("#table2 tbody input[@type=checkbox]").attr("checked", o.checked);
}


window.onload = function() {

var tablename = document.getElementById('table2');
tablename.rows[1].cells[0].rowSpan = '6';
for (var i = 2; i < 7; i++) {
    tablename.rows[i].cells[0].style.display = 'none';
}
tablename.rows[7].cells[0].rowSpan = '7';
for (var i = 8; i < 14; i++) {
    tablename.rows[i].cells[0].style.display = 'none';
}

var tabnumn = 0;
var tablename = 'table2';
for (var i = 1; i < document.getElementById(tablename).rows.length - 2; i++) {
    if (document.getElementById(tablename).rows[i].cells[1].childNodes[0].checked || document.getElementById(tablename).rows[i].cells[1].childNodes[0].disabled) {
        tabnumn += parseInt(document.getElementById(tablename).rows[i].cells[6].childNodes[0].value == '' ? '0' : parseInt(document.getElementById(tablename).rows[i].cells[6].childNodes[0].value));
    }
}

document.getElementById('txtallnum2').value = tabnumn;
}



function Knum(obj, tablename, n) {
    var rowIndex = obj.parentNode.parentNode.rowIndex;
    var tbcell3 = document.getElementById(tablename).rows[rowIndex].cells[3].innerHTML; //分值
    var tbcell4 = document.getElementById(tablename).rows[rowIndex].cells[7].innerHTML; //数量
    var tbcell5 = document.getElementById(tablename).rows[rowIndex].cells[4].childNodes[0].value; //最高分
    var tbcell6 = document.getElementById(tablename).rows[rowIndex].cells[5].childNodes[0].value; //完成数量
    var tbcell7 = document.getElementById(tablename).rows[rowIndex].cells[6].childNodes[0].value; //单项总分
    var tbcell0 = document.getElementById(tablename).rows[rowIndex].cells[1].childNodes[0].checked;
    var checkdisabled = document.getElementById(tablename).rows[rowIndex].cells[1].childNodes[0].disabled; //是否默认菜单项
    var hidQuantity = document.getElementById(tablename).rows[rowIndex].cells[1].childNodes[12].value; //完成数量 hid
  
    if (checkdisabled) {
        if (parseInt(obj.value) < parseInt(hidQuantity)) {
            obj.value = hidQuantity;
         }        
    }
    else {
        if (!tbcell0) {//如果打勾false则都为0
            document.getElementById(tablename).rows[rowIndex].cells[5].childNodes[0].value = '0'; //完成数量
            document.getElementById(tablename).rows[rowIndex].cells[6].childNodes[0].value = '0'; //单项总分
        } 
    }
    var Agg = 0;

    if (tbcell5 == 0) {

        Agg = parseInt(obj.value) / parseInt(tbcell4) * parseInt(tbcell3);

        document.getElementById(tablename).rows[rowIndex].cells[6].childNodes[0].value = parseInt(Agg);
    }
    else {

        Agg = parseInt(obj.value) / parseInt(tbcell4) * parseInt(tbcell3);

        if (Agg > parseInt(tbcell5 == 'NaN' ? '0' : tbcell5)) {

            document.getElementById(tablename).rows[rowIndex].cells[6].childNodes[0].value = parseInt(tbcell5 == NaN ? '0' : tbcell5)
        }
        else
        { document.getElementById(tablename).rows[rowIndex].cells[6].childNodes[0].value = parseInt(Agg); }
    }
    if (tbcell6 == '') {
        document.getElementById(tablename).rows[rowIndex].cells[5].childNodes[0].value = '0';

    }

    //            else {
    //document.getElementById(tablename).rows[rowIndex].cells[6].childNodes[0].value = (Agg == NaN ? '0' : Agg);

    //}
    if (document.getElementById(tablename).rows[rowIndex].cells[6].childNodes[0].value == 'NaN') {
        document.getElementById(tablename).rows[rowIndex].cells[6].childNodes[0].value = '0'
    }
    var tabnumn = 0;

    for (var i = 1; i < document.getElementById(tablename).rows.length - 2; i++) {
        if (document.getElementById(tablename).rows[i].cells[1].childNodes[0].checked || document.getElementById(tablename).rows[i].cells[1].childNodes[0].disabled) {
            tabnumn += parseInt(document.getElementById(tablename).rows[i].cells[6].childNodes[0].value == '' ? '0' : parseInt(document.getElementById(tablename).rows[i].cells[6].childNodes[0].value));
        }
        
    }

    document.getElementById('txtallnum' + n).value = tabnumn;
    if (parseInt(document.getElementById('txtallnum' + n).value) > parseInt(document.getElementById('txtTotal' + n).value)) {
        //document.getElementById('btnAdd').value = "保存工作设置(设置分数大于最低分数)";
    }
    else {
        //document.getElementById('btnAdd').value = "保存工作设置(设置分数小于最低分数)";
    }

}